package com.wxx.controller.bg;

import com.wxx.model.DicAcl;
import com.wxx.service.bg.DicAclService;
import com.wxx.vo.DicAclListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/bg/dicAcl/")
public class DicAclController {

    @Autowired
    private DicAclService dicAclService;


    /**
     * 根据父级id找子级
     * @return
     */
    @RequestMapping(value = "findAclByParentId",method = RequestMethod.POST)
    @ResponseBody
    public Object findAclByParentId(Model model, String id){
        Map map = dicAclService.findAclByParentId(id);
        return map;
    }

    /**
     * 删除权限
     * @return
     */
    @RequestMapping(value = "del",method = RequestMethod.POST)
    @ResponseBody
    public Object del(Model model, String aclId){
        Map map = dicAclService.del(aclId);
        return map;
    }

    /**
     * 跳转到编辑权限页面
     * @return
     */
    @RequestMapping(value = "toEdit",method = RequestMethod.GET)
    public String goEdit(Model model, String aclId){
        Map map = dicAclService.goEdit(aclId);
        //查询次级菜单
        List<DicAcl> dicAclList = (List<DicAcl>) map.get("dicAclList");
        //查询编辑对象
        DicAcl dicAcl = (DicAcl) map.get("dicAcl");

        model.addAttribute("list",dicAclList);
        model.addAttribute("model",dicAcl);
        return "dicAcl/edit";
    }

    /**
     * 编辑权限
     * @return
     */
    @RequestMapping(value = "edit",method = RequestMethod.POST)
    @ResponseBody
    public Object edit(Model model, DicAcl dicAcl){
        Map map = dicAclService.edit(dicAcl);
        return map;
    }

    /**
     * 跳转到添加权限页面
     * @return
     */
    @RequestMapping(value = "toAdd",method = RequestMethod.GET)
    public String toAdd(Model model){
        List<DicAcl> totalAclList = dicAclService.findTotalAcl();
        model.addAttribute("list",totalAclList);
        return "dicAcl/add";
    }

    /**
     * 添加权限
     * @return
     */
    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ResponseBody
    public Object add(Model model, DicAcl dicAcl, String parentId2){
        Map map = dicAclService.add(dicAcl,parentId2);
        return map;
    }

    /**
     * 跳转到权限列表页面
     * @return
     */
    @RequestMapping(value = "toDicAclList",method = RequestMethod.GET)
    public String toDicAclList(Model model){
        List<DicAclListVo> dicAclListVoList = dicAclService.findDicAclList();
        model.addAttribute("list",dicAclListVoList);
        return "dicAcl/list";
    }

}
